//
//  AIFCheckSmsCodeManager.m
//  PywSdk
//
//  Created by smallwave on 16/4/13.
//  Copyright © 2016年 zero. All rights reserved.
//

#import "AIFCheckSmsCodeManager.h"

@implementation AIFCheckSmsCodeManager

NSString *const CheckSmsCode_PASSPORT = @"passport";
NSString *const CheckSmsCode_PASSPORT_TOKEN = @"passport_token";
NSString *const CheckSmsCode_SMSCODE = @"smscode";
NSString *const CheckSmsCode_TID = @"tid";
NSString *const CheckSmsCode_GAMEID = @"gameid";
NSString *const CheckSmsCode_SIGN = @"sign";
NSString *const CheckSmsCode_SMSTYPE = @"smstype";

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.child = self;
        self.paramSource = self;
        self.validate = self;
    }
    return self;
}


#pragma mark - ETAPIManager
- (NSString *)methodName{
    return URL_CHECKSMSCODE;
}

- (ETAPIManagerRequestType)requestType{
    return ETAPIManagerRequestTypePost;
}


- (NSString *)seriviceType{
    return [PywAppInfo sharedAppInfo].seriviceType;
}


#pragma mark - ETAPIManagerParamSourceDelegate
- (NSDictionary *)paramsForApi:(ETApiBaseManager *)manager{
    
    NSString * passport = self.phoneNum;
    NSString * smscode = self.smsCode;
    NSString * gameid = [PywAppInfo sharedAppInfo].gameId;
    
    NSString * tid = [PywAppInfo sharedAppInfo].tid;
    NSString * apiSecret2 = [AppUtil getApiSecret2:tid apiSecret:[PywAppInfo sharedAppInfo].apisecret];
    NSString * sign = [PywCipherUtils md5:[NSString stringWithFormat:@"%@%@%@",gameid,passport,apiSecret2]];
    
    NSString * smstype = self.smsType;
    
    MutableDictionary *param = [[MutableDictionary alloc] init];
    if ([smstype isEqualToString:@"4"]) {
        // smsType = 4 才传
        NSString * passport_token = [PywPlatformMain sharedPlatformMain].passport_Token;
        [param setObject:passport_token forKey:CheckSmsCode_PASSPORT_TOKEN];
    }
    [param setObject:passport forKey:CheckSmsCode_PASSPORT];
    [param setObject:smscode forKey:CheckSmsCode_SMSCODE];
    [param setObject:gameid forKey:CheckSmsCode_GAMEID];
    [param setObject:tid forKey:CheckSmsCode_TID];
    [param setObject:sign forKey:CheckSmsCode_SIGN];
    [param setObject:smstype forKey:CheckSmsCode_SMSTYPE];
    return param;
}

#pragma mark - ETAPIManagerValidator
- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithParamsData:(NSDictionary *)data{
    return YES;
}

- (BOOL)manager:(ETApiBaseManager *)manager isCorrectWithCallBackData:(NSDictionary *)data{
    return YES;
}

@end
